// action类型名称
export const ADD_TODO = 'ADD_TODO'; // 添加事项
export const TOGGLE_TODO = 'TOGGLE_TODO'; // 切换事项状态
export const DELETE_TODO = 'DELETE_TODO'; // 删除事项
export const SET_VISIBILITY_FILTER = 'SET_VISIBILITY_FILTER'; // 设置可见事项的过滤值

// 过滤类型常量
export const VisibilityFilters = {
	SHOW_ALL: 'SHOW_ALL', // 全显示
	SHOW_ACTIVE: 'SHOW_ACTIVE', // 只显示未完成的
	SHOW_COMPLETED: 'SHOW_COMPLETED' // 只显示已完成的
}

// 设置todoId初始值为0
let nextTodoId = 0

// 添加待办项 actionCreator函数
export const addTodo = (text) => ({
	type: ADD_TODO,
	id: nextTodoId++,
	text
})

// 切换事项状态 actionCreator函数
export const toggleTodo = (id) => ({
	type: TOGGLE_TODO,
	id
})

// 删除事项 actionCreator函数
export const deleteTodo = (id) => ({
	type: DELETE_TODO,
	id
})

// 设置可见事项的过滤值 actionCreator函数
export const setVisibilityFilter = (filter) => ({
	type: SET_VISIBILITY_FILTER,
	filter
})